package cn.tangwei.user.controller;

import cn.tangwei.basic.utils.AjaxRusult;
import cn.tangwei.user.domain.LoginInfo;
import cn.tangwei.user.service.ILoginInfoService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/loginInfo")
@Api(tags = "门户网站接口",description = "门户网站接口详细描述")
public class LoginInfoContorller {
    @Autowired
    private ILoginInfoService loginInfoService;

    /**
     * 添加和修改
     * @param loginInfo
     * @return
     */
    @PutMapping
    public AjaxRusult addOrUpdate(@RequestBody LoginInfo loginInfo){
        try {
            if(loginInfo.getId() == null){
                loginInfoService.add(loginInfo);
            }else {
                loginInfoService.update(loginInfo);
            }
            return AjaxRusult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxRusult.me().setMessage("操作失败");
        }
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public AjaxRusult delete(@PathVariable("id") Long id){
        try {
            loginInfoService.delete(id);
            return AjaxRusult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxRusult.me().setMessage("操作失败");
        }
    }

    /**
     * 查询一条
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public LoginInfo queryById(@PathVariable("id") Long id){
        return loginInfoService.queryById(id);
    }

    /**
     * 查询全部
     * @return
     */
    @GetMapping
    public List<LoginInfo> queryAll(){
        return loginInfoService.queryAll();
    }

}
